package cn.kgc.service.impl;

import cn.hutool.crypto.digest.BCrypt;
import cn.kgc.entity.Admin;
import cn.kgc.mapper.AdminMapper;
import cn.kgc.service.AdminService;
import cn.kgc.utils.JwtUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author YC
 */
@Service("adminService")
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    private static final Logger log = LoggerFactory.getLogger(AdminServiceImpl.class);
    @Resource
    private JwtUtil jwtUtil;

    public AdminServiceImpl() {
    }

    @Override
    public Admin adminLogin(String adminName, String adminPassword) {
        Admin admin = baseMapper.selectOne(new LambdaQueryWrapper<Admin>().eq(Admin::getUsername, adminName));
        if (admin != null && BCrypt.checkpw(adminPassword, admin.getPassword())) {
            admin.setPassword("");
            return admin;
        } else {
            return null;
        }
    }
}
